package cn.edu.ctbu.controller.admin;

import cn.edu.ctbu.DTO.DishDetailDTO;
import cn.edu.ctbu.VO.DishDetailVO;
import cn.edu.ctbu.VO.PageDishVO;
import cn.edu.ctbu.entity.Dish;
import cn.edu.ctbu.result.PageResult;
import cn.edu.ctbu.result.Result;
import cn.edu.ctbu.service.IDishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关接口")
public class DishController {
    @Autowired
    IDishService iDishService;

    /**
     * 分页查询菜品
     */
    @ApiOperation("分类查询菜品")
    @GetMapping
    public Result<PageResult> get(Integer page,Integer pageSize,String name,Long categoryId,Integer status){
        PageResult list=iDishService.get(page,pageSize,name,categoryId,status);
        return Result.success(list);
    }

    /**
     * 是否禁用
     */
    @ApiOperation("启动禁用分类")
    @GetMapping("/status")
    public Result status(Long id){
        iDishService.status(id);
        return Result.success();
    }

    /**
     *根据ID获得菜品详情
     */
    @ApiOperation("根据ID获得菜品详情")
    @GetMapping("/add/{id}")
    public Result<DishDetailVO> getDishDetail(@PathVariable Long id){
        DishDetailVO vo=iDishService.getDishDetail(id);
        return Result.success(vo);
    }

    /**
     * 新增菜品
     */
    @ApiOperation("新增菜品")
    @PostMapping("/add")
    public Result add(@RequestBody DishDetailDTO dto){
        iDishService.add(dto);
        return Result.success();
    }

    /**
     * 更新菜品
     */
    @ApiOperation("更新菜品")
    @PutMapping("/put")
    public Result put(@RequestBody DishDetailDTO dto){
        iDishService.put(dto);
        return Result.success();
    }

    /**
     * 删除菜品
     */
    @ApiOperation("删除菜品")
    @DeleteMapping("/delete")
    public Result del(@RequestBody List<Long> ids){
        iDishService.del(ids);
        return Result.success();
    }

    /**
     * 根据分类ID获得菜品列表
     */
    @ApiOperation("根据分类ID获得菜品")
    @GetMapping("/category")
    public Result<List<Dish>> Category(Long categoryId){
        List<Dish> list=iDishService.getByCategory(categoryId);
        return Result.success(list);
    }


}
